package com.example.mcp.config;


import com.example.service.StudentService;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * MCP服务器配置类，负责注册MCP工具
 */
@Configuration
public class McpServerConfig {


    @Bean
    public ToolCallbackProvider studentToolCallbackProvider(StudentService studentService) {
        // 打印传入的 studentService 实例
        System.out.println("studentService 实例: " + studentService.getClass().getName());
        MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
                .toolObjects(studentService)
                .build();

        // 通过反射获取工具名称
        Arrays.stream(provider.getToolCallbacks())
                .map(ToolCallback::getName)
                .forEach(name -> System.out.println("注册的工具Registered Tool: " + name));
        return provider;
    }

}
